package com.hu.config.rabbitMQ;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Bean//注册一个，hello是队列名称，简单的
    public Queue helloQueue() {
        return new Queue("hello");
    }

    @Bean
    public Queue hiQueue() {
        return new Queue("hi");
    }

    /**
     *  topic
     */
//    @Bean
//    TopicExchange exchange() {
//        return new TopicExchange("exchange");
//    }
//
//    @Bean
//    Binding bindingExchangeMessage(Queue helloQueue, TopicExchange exchange) {
//        return BindingBuilder.bind(helloQueue).to(exchange).with("hello");
//    }
//
//    @Bean
//    Binding bindingExchangeMessages(Queue hiQueue, TopicExchange exchange) {
//        return BindingBuilder.bind(hiQueue).to(exchange).with("*");
//    }

    /**
     * fanout
     */
    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("fexchange");
    }

    @Bean
    Binding bindingExchangeA(Queue helloQueue,FanoutExchange fexchange) {
        return BindingBuilder.bind(helloQueue).to(fexchange);
    }

    @Bean
    Binding bindingExchangeB(Queue hiQueue, FanoutExchange fexchange) {
        return BindingBuilder.bind(hiQueue).to(fexchange);
    }

}